package com.drinkdelivery.web.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
//import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.drinkdelivery.common.annotation.Log;
import com.drinkdelivery.common.core.controller.BaseController;
import com.drinkdelivery.common.core.domain.AjaxResult;
import com.drinkdelivery.common.enums.BusinessType;
import com.drinkdelivery.common.domain.ProductSpec;
import com.drinkdelivery.service.IProductSpecService;
import com.drinkdelivery.common.utils.poi.ExcelUtil;
import com.drinkdelivery.common.core.page.TableDataInfo;

/**
 * 商品规格属性Controller
 *
 * @author lzh
 * @date 2024-11-08
 */
@Api(tags = "商品规格属性Controller")
@RestController
@RequestMapping("/admin/spec")
public class ProductSpecController extends BaseController
{
    @Autowired
    private IProductSpecService productSpecService;

    /**
     * 查询商品规格属性列表
     */
    @ApiOperation(value = "查询商品规格属性列表")
//@PreAuthorize("@ss.hasPermi('drinkdelivery:spec:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductSpec productSpec)
    {
        startPage();
        List<ProductSpec> list = productSpecService.selectProductSpecList(productSpec);
        return getDataTable(list);
    }

    /**
     * 导出商品规格属性列表
     */
    @ApiOperation(value = "导出商品规格属性列表")
    //@PreAuthorize("@ss.hasPermi('drinkdelivery:spec:export')")
    @Log(title = "商品规格属性", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductSpec productSpec)
    {
        List<ProductSpec> list = productSpecService.selectProductSpecList(productSpec);
        ExcelUtil<ProductSpec> util = new ExcelUtil<ProductSpec>(ProductSpec.class);
        util.exportExcel(response, list, "商品规格属性数据");
    }

    /**
     * 获取商品规格属性详细信息
     */
    @ApiOperation(value = "获取商品规格属性详细信息")
    //@PreAuthorize("@ss.hasPermi('drinkdelivery:spec:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(productSpecService.selectProductSpecById(id));
    }

    /**
     * 新增商品规格属性
     */
    @ApiOperation(value = "新增商品规格属性")
    //@PreAuthorize("@ss.hasPermi('drinkdelivery:spec:add')")
    @Log(title = "商品规格属性", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductSpec productSpec)
    {
        return toAjax(productSpecService.insertProductSpec(productSpec));
    }

    /**
     * 修改商品规格属性
     */
    @ApiOperation(value = "修改商品规格属性")
    //@PreAuthorize("@ss.hasPermi('drinkdelivery:spec:edit')")
    @Log(title = "商品规格属性", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductSpec productSpec)
    {
        return toAjax(productSpecService.updateProductSpec(productSpec));
    }

    /**
     * 删除商品规格属性
     */
    @ApiOperation(value = "删除商品规格属性")
    //@PreAuthorize("@ss.hasPermi('drinkdelivery:spec:remove')")
    @Log(title = "商品规格属性", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(productSpecService.deleteProductSpecByIds(ids));
    }
}
